package com.huawei.petSystemdemo;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.huawei.petSystemdemo.bean.Pets;
import com.huawei.petSystemdemo.bean.Shopping;
import com.huawei.petSystemdemo.bean.User;

import java.util.ArrayList;
import java.util.List;

public class GlobalViewModel extends ViewModel {
    private static GlobalViewModel globalViewModel;
    public User user;

    public final MutableLiveData<List<Pets>> seleted = new MutableLiveData<>();

    public final MutableLiveData<List<Shopping>> shoppingSelected = new MutableLiveData<>();

    public boolean isLogin() {
        return user != null;
    }

    int id;
    int username;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getUsername() {
        return username;
    }

    public void setUsername(int username) {
        this.username = username;
    }



    public static GlobalViewModel getGlobal() {
        if (globalViewModel == null)
            globalViewModel = new GlobalViewModel();

        return globalViewModel;
    }

    private GlobalViewModel() {
        seleted.setValue(new ArrayList<>());
        shoppingSelected.setValue(new ArrayList<>());
    }

    public double getTotalPrice() {
        double total = 0;
        for (Pets pet : seleted.getValue()) {
            total += pet.getPrice();
        }
        return total;
    }
}
